//品牌管理
$(function(){
	$('#backUserList').getList({
		"initData":{
			"num":1,
			"size":10
		},
		"url":site.apiUrl+"/back/backUser/selectBackUserList",// 数据请求url
		"type":"get",
		"ajaxform":true,
		"checkname":"datachk", //选择器名称，为空不显示选择器
		"col":[  //数据列
			{"field":"account","display":"账户","width":"1.5"},
			{"field":"nickName","display":"昵称","width":"1.5"},
			{"field":"userHeadPicUrl","display":"用户头像","width":"1.5","fun":"changePic"},
			// {"field":"userTypeDisplay","display":"用户类型","width":"2"},
//			{"field":"businessName","display":"使用商家","width":"2"},
			{"field":"isUsingDisplay","display":"是否启用","width":"1.5"},
			{"field":"createTime","display":"创建时间","width":"1.5"}
		],
		"option":[ //操作按钮配置
			{"icon":"more","tip":"重置密码","fun":"backUserView('{{id}}')"},  //icon: view,edit,add,del*/
			{"icon":"edit","tip":"编辑","fun":"backUserEdit('{{id}}')"},  // 花括号内可以对应相关字段
			{"icon":"setrules","tip":"设置权限","url":"backUser/set_menu.html?id={{id}}&nickName={{nickName}}"},
			{"icon":"del","tip":"删除","fun":"deleteBackUser('{{id}}')"}
		]
	});

	//批量删除
	$("#batchDelBtn").click(function(){
		var c = "";
		$("input[name=datachk]:checked").each(function(){
			c += $(this).val()+',';
		});
		if(c!= null && c!=''){
			deleteBackUser(c);
		}else{
			ly.toast("请选择删除项");
		}
		
	});
});
//编辑
function backUserEdit(id){
	ly.goto("backUser/scenic_backUser_create.html?id="+id+"&backUserType=2")
}

//删除
function deleteBackUser(id){
	var url = site.gateUrl+"/back/backUser/deleteBackUserById";
	console.log(id);
	ly.confirm("你确认删除吗？",function(){
		request({
			url:url,
			data:{"ids":id},
			type:"get",
			ajaxform:true,
			callback:function(f) {
				console.log(f);
				if(f.code=="rest.success"){
					ly.toast("删除成功");
					$("#backUserList").getList.refresh();//刷新当前分页

				}
			}
		});
	});

}

//查看
function backUserView(id){
	
	ly.confirm("您确定重置密码？",function(){
		var url = site.gateUrl+"/back/backUser/resetPassword";
		request({
		url:url,
		data:{"id":id},
		type:"post",
		ajaxform:true,
		callback:function(f) {
			console.log(f);
			if(f.code=="rest.success"){
				ly.toast("重置成功");
				$("#backUserList").getList.refresh();//刷新当前分页
				
			}
		}
	});	
	});
	
}

function changePic(v, o, d) {
	if(d.userHeadPicUrl!=null && d.userHeadPicUrl!= ''){
		$(o).html("<img src='"+d.userHeadPicUrl+"' width='30' height='30'>");
	}else{
		$(o).html("<img src='"+site.interUrl+"img/default_head.jpg' width='30' height='30'>");
	}
    
}